package com.ruoyi.manage.service.impl;

import java.util.List;

import com.alibaba.fastjson.JSONObject;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.manage.mapper.TeamMapper;
import com.ruoyi.manage.domain.Team;
import com.ruoyi.manage.service.ITeamService;

/**
 * 团队Service业务层处理
 * 
 * @author ruoyi
 * @date 2021-03-07
 */
@Service
public class TeamServiceImpl implements ITeamService 
{
    @Autowired
    private TeamMapper teamMapper;

    /**
     * 查询团队
     * 
     * @param id 团队ID
     * @return 团队
     */
    @Override
    public Team selectTeamById(Long id)
    {
        Team team = teamMapper.selectTeamById(id);
        String imageList = team.getImageList();
        List list = JSONObject.parseObject(imageList, List.class);
        team.setImageListOb(list);
        return team;
    }

    /**
     * 查询团队列表
     * 
     * @param team 团队
     * @return 团队
     */
    @Override
    public List<Team> selectTeamList(Team team)
    {
        return teamMapper.selectTeamList(team);
    }

    /**
     * 新增团队
     * 
     * @param team 团队
     * @return 结果
     */
    @Override
    public int insertTeam(Team team)
    {
        List<String> imageListOb = team.getImageListOb();
        String imageList = JSONObject.toJSONString(imageListOb);
        team.setImageList(imageList);
        team.setCreateTime(DateUtils.getNowDate());
        return teamMapper.insertTeam(team);
    }

    /**
     * 修改团队
     * 
     * @param team 团队
     * @return 结果
     */
    @Override
    public int updateTeam(Team team)
    {
        List<String> imageListOb = team.getImageListOb();
        String imageList = JSONObject.toJSONString(imageListOb);
        team.setImageList(imageList);
        return teamMapper.updateTeam(team);
    }

    /**
     * 批量删除团队
     * 
     * @param ids 需要删除的团队ID
     * @return 结果
     */
    @Override
    public int deleteTeamByIds(Long[] ids)
    {
        return teamMapper.deleteTeamByIds(ids);
    }

    /**
     * 删除团队信息
     * 
     * @param id 团队ID
     * @return 结果
     */
    @Override
    public int deleteTeamById(Long id)
    {
        return teamMapper.deleteTeamById(id);
    }
}
